import { RequestTypes } from "@/const";

function url(s) {
  return `${window.RPConfig.baseURL}/sys/org/${s}`;
}
function url2(s) {
  return `${window.RPConfig.mgt}/org/${s}`;
}
function organizationUrlAppend(s) {
  return `${window.RPConfig.mgt}/organization/${s}`;
}
function departmentUrlAppend(s) {
  return `${window.RPConfig.mgt}/department/${s}`;
}
function url5(s) {
  return `${window.RPConfig.mgt}/company/${s}`;
}
function url6(s) {
  return `${window.RPConfig.mgt}/position/${s}`;
}
function url7(s) {
  return `${window.RPConfig.mgt}/job/${s}`;
}
function url8(s) {
  return `${window.RPConfig.mgt}/employee/${s}`;
}

// ---------组织架构-组织----------
// 搜索
export const searchOrgTree = val => $http.get(organizationUrlAppend("findOrganizationByCondition?nameOrCode=" + val));
// 获取树列表
export const getOrgTreeList = params => {
  params.requestType = RequestTypes.Query;
  return $http.post(organizationUrlAppend(`getOrgTreeByUser?orgType=${1}`), params);
};
// 获取树列表详情
export const getOrgTreeListDetail = id => $http.get(organizationUrlAppend("findOrgById?orgId=" + id));
// 获取组织名称国际化(多语言)
export const getOrgNameLangList = id => $http.get(organizationUrlAppend("name/lang/list?orgId=" + id));
// 修改组织名称国际化(多语言)
export const updateOrgNameLangList = param => $http.post(organizationUrlAppend("name/lang/update"), param);
// 修改树节点的时候-获取路径
export const getOrgPath = id => $http.get(organizationUrlAppend("getOrgPath?orgId=" + id));

// 更新树节点
export const updateOrgNode = param => $http.post(organizationUrlAppend("update"), param);

// 新建树节点
export const addOrgNode = param => $http.post(organizationUrlAppend("add"), param);
// 新建树节点的时候-获取路径
export const getOrgPathWhenCreate = id => $http.get(organizationUrlAppend("getOrgPathWhenCreate?orgId=" + id));
// 获取多语言
export const getLang = id => $http.get(organizationUrlAppend("name/lang/list?orgId=" + id));

// ---------组织架构-部门----------
// 获取部门树列表
export const getDeptTreeList = params => {
  return $http.get(departmentUrlAppend("findDepartmentListByPid"), params);
};
// 新建部门
export const addDept = param => $http.post(departmentUrlAppend("add"), param);

// 更新部门
export const updateDept = param => $http.post(departmentUrlAppend("update"), param);
// 搜索
export const searchDeptTree = param => $http.get(departmentUrlAppend("findDepartmentByNameOrCode"), param);
// ---------公司信息----------
// 公司信息表格列表
export const getCompanyList = ({ responseProcess, param }) => {
  $http.post(url5("list/page"), param).then(res => {
    responseProcess(res.data);
  });
};
export const addCompany = param => $http.post(url5("add"), param);
// 获取关联公司
export const getCompany = param => $http.post(url5(`list?ids=${param.ids}`), param);
export const updateCompany = param => $http.post(url5("update"), param);

// ---------职位管理----------
// 获取职位树列表
// export const getPositionTreeList = id => $http.get(url4("findDepartmentListByPid?deptId=" + id));
export const getPositionInfo = param => $http.post(url6("page/query"), param);

// 新建职位
export const addPosition = param => $http.post(url6("add"), param);

// 编辑职位
export const updatePosition = param => $http.post(url6("update"), param);

// 根据职位编码查询子节点
export const getTableChildrenData = param => $http.post(url6("findChildByCode?code=") + param);

// 根据职位编码 查询子节点
export const getPositionTreeList = param => $http.post(url6("findChildByCode"), param);

// 查询所有职务
export const getAllJob = param => $http.post(url7("page/query"), param);

// 获取已分配人员
export function getAssign(param) {
  return $http.post(url8("job/list/page"), param).then(res => res.data);
}

// 获取未分配人员
export function getNotAssign(param) {
  return $http.post(url8("list/page/position"), param).then(res => res.data);
}

// 分配人员
export const addEmp = param => $http.post(url6("addEmp"), param);

// 移除人员
export const deleteEmp = param => $http.post(url6("deleteEmp"), param);

// 主职兼职切换
export const change = param => $http.post(url8("job/updateMainPost"), param);

// 已存在主职的情况下，强制切换为主职
export const forceChange = param => $http.post(url8("job/forceUpdateMainPost"), param);

export const queryOrgsByOrgPaths = param =>
  $http.post(`${window.RPConfig.mgt}/organization/listOrganizationsByOrgPaths`, param).then(res => res.data);

export const getLowcodeDataSyncEnable = param =>
$http.post(`${window.RPConfig.mgt}/applicationSync/lowcodeDataSyncEnable`).then(res => res.data);

export const getUserSofts = param =>
$http.get(`${window.RPConfig.mgt}/applicationSync/softs`, param).then(res => res.data);

export const postPevelopUserAuth = param =>
$http.post(`${window.RPConfig.mgt}/roleSync/developUserAuth`, param).then(res => res.data);

export const getDevelopUserList = param =>
$http.post(`${window.RPConfig.mgt}/userSync/getDevelopUserListPages`, param, null).then(res => res);

// 授权开发者角色给用户：租户管理员
export const authorizationToUser = param =>
$http.post(`${window.RPConfig.mgt}/roleSync/authorizeDevelopRoleForUsers`, param).then(res => res.data);

export const getMainDataByOrgid = param =>
$http.get(organizationUrlAppend("getOrgsMdmData"), param).then(res => res.data);

